package org.haq.bae.data;

import org.haq.bae.datamodel.EntityModel;
import org.haq.bae.datamodel.Validatable;
import org.haq.bae.manager.DatasourceManager;
import org.haq.bae.runtime.core.Datasource;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Database Metadata Access
 */
public class DbMetaAccess implements Validatable {

    private final Map<String, EntityModel> modelMap = new LinkedHashMap<String, EntityModel>();
    private String currentDatasourceName;
    private Datasource currentDatasource;

    public DbMetaAccess(String datasouceName) {
        this.currentDatasourceName = datasouceName;
        if (!isValid()) {
            throw new IllegalArgumentException("Datasource " + datasouceName + " is not registered");
        }
    }

    public EntityModel getEntityModel(String dbEntityName) {


        return null;

    }

    public Map<String, EntityModel> getEntityModels() {

        return modelMap;
    }

    @Override
    public boolean isValid() {
        if (DatasourceManager.getInstance().getDatasource(currentDatasourceName) == null) {
            return false;
        }

        currentDatasource = DatasourceManager.getInstance().getDatasource(currentDatasourceName);
        return true;
    }
}
